package com.reds.backend.service.impl.check;
import com.alibaba.fastjson2.JSONObject;
import com.reds.backend.service.check.checkShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class checkShowServiceImpl implements checkShowService {
    @Autowired
    public RestTemplate template;

    private String getArticleUrl = "http://124.221.73.180:3002/check/getArticle/";
    private String showAllArticleByStateURL = "http://124.221.73.180:3002/check/showAllArticleByState/";
    private String UnCheckurl = "http://124.221.73.180:3002/check/showMyUncheck/";
    private String Allurl = "http://124.221.73.180:3002/check/allCheck/";

    @Override
    public String getArticle(int id) {
        MultiValueMap<String,String> map =new LinkedMultiValueMap<>();
        map.add("id",id+"");
        JSONObject jsonObject = template.postForObject(getArticleUrl,
                map,
                JSONObject.class);
        System.out.println(jsonObject);
        return jsonObject.toJSONString();
    }

    @Override
    public JSONObject showAllArticleByState(String state,int page,int sizes) {
        MultiValueMap<String,String> map =new LinkedMultiValueMap<>();
        map.add("state",state);
        map.add("page",page+"");
        map.add("sizes",sizes+"");
        JSONObject jsonObject = template.postForObject(showAllArticleByStateURL,
                map,
                JSONObject.class);
        return jsonObject;
    }

    @Override
    public JSONObject showMyUncheck(String author,int page,int sizes) {
        MultiValueMap<String,String> map =new LinkedMultiValueMap<>();
        map.add("author",author);
        map.add("page",page+"");
        map.add("sizes",sizes+"");
        JSONObject jsonObject = template.postForObject(UnCheckurl,
                map,
                JSONObject.class);
        return jsonObject;
    }

    @Override
    public JSONObject showAll(int page, int sizes) {
        MultiValueMap<String,String> map =new LinkedMultiValueMap<>();
        map.add("page",page+"");
        map.add("sizes",sizes+"");
        JSONObject jsonObject = template.postForObject(Allurl,
                map,
                JSONObject.class);
        return jsonObject;
    }
}
